<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>upload file</title>
<link rel="stylesheet" type="text/css" href="css/test.css">
</head>
<body>

<%! String currentUser = null; %>
<%
//判断是否已经有用户登录
	currentUser = (String)session.getAttribute("currentUser");
	if(null != currentUser)
	{
		out.print("<p id='welcomeInfo'> 当前登录用户："+currentUser+" <a href='/ImageTest/test.jsp'>退出当前用户</a></p>");
	}
	
%>

<%
	//限制未登录用户不能查看本页面内容
	session = request.getSession();
	String hasLogin = (String)session.getAttribute("hasLogin");
	if(!"hasLogined".equals(hasLogin))
	{
		request.setAttribute("hasLogin", "请先登录，才可以上传图片!");
		ServletContext sc = getServletContext();
        RequestDispatcher rd = null;
        rd = sc.getRequestDispatcher("/login.jsp");//
        rd.forward(request, response);
		return;
	}
%>

<div id="header"></div>

<ul id="nav">
<li><a href="/ImageTest/index.jsp">首页</a></li>
<li><a href="/ImageTest/viewImage.jsp">看图片</a></li>
<li><a href="/ImageTest/upload_file.jsp">上传图片</a></li>
<li><a href="/ImageTest/login.jsp">登录</a></li>
<li><a href="/ImageTest/regist.jsp">注册用户</a></li>
<li><a href="/ImageTest/administor.jsp">管理员</a></li>
</ul>

<div id="content">
<form action="FileUploadSvr"  enctype="multipart/form-data" method="post">
<input type="file" name="upload1" value="选择文件">
<input type="submit" value="上传文件">
</form>
</div>

<%
	//判断上传文件是否成功
	String error = (String)request.getAttribute("Error");
	if(null != error)
	{
		if("success".equals(error))
		{
			out.print("<p id='errinfo'>"+(String)request.getAttribute("fileName")+"上传成功<p>");
		}
	}
%>
</body>
</html>